package config

import (
	"fmt"
	"github.com/jinzhu/gorm"
)

var MysqlDB = map[string]string{
	"type":      "mysql",
	"host":      "localhost",
	"port":      "3306",
	"database":  "test",
	"user":      "root",
	"password":  "root",
	"prefix":    "go_",
	"agreement": "tcp",
	"parameter": "charset=utf8&parseTime=True",
}

// MySQL驱动链接数据库
// var ConnectionString = fmt.Sprintf("%s:%s@%s(%s:%s)/%s", DB["user"], DB["password"], DB["agreement"], DB["host"], DB["port"], DB["database"])
// gorm链接数据库 user:password@/dbname?charset=utf8&parseTime=True&loc=Local
var ConnectionString = fmt.Sprintf("%s:%s@/%s?%s",
	MysqlDB["user"],
	MysqlDB["password"],
	MysqlDB["database"],
	MysqlDB["parameter"])

func init() {
	gorm.DefaultTableNameHandler = func(db *gorm.DB, defaultTableName string) string {
		return "go_" + defaultTableName
	}
}

const SingularTable = true
